package com.qdlc.p2p.biz.executer.impl;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.executer.BaseExecuter;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 冻结或解冻还款人资金
 *
 * @author cx
 * @version 2.0
 * @since 2014-5-21
 */
@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class BorrowRepayFreezeExecuter extends BaseExecuter {

    @Override
    public String getAccountLogType() {
        return (super.money) > 0 ? LogTplNid.FREEZE : LogTplNid.UNFREEZE;
    }

    @Override
    public void handleAccountWithLog() {
        String accountLogType = getAccountLogType();
        Global.setTransfer(LogTplNid.LOG_TPL_KEY, accountLogType);
        Global.setTransfer("web_url", WEB_URL);
        if (LogTplNid.FREEZE.equals(accountLogType)) {
            accountService.freeze(super.user.getUserId(), SystemConfigs.ADMIN_ID, super.money);
        } else {
            accountService.unFreeze(super.user.getUserId(), SystemConfigs.ADMIN_ID, super.money);
        }
    }
}
